package com.lemon.funplus.view;

import static android.view.Gravity.START;
import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.funplus.R;

public class CustomActionbar extends RelativeLayout {
	private LayoutInflater layoutInflater;
	RelativeLayout mActionLayout;
	ImageView menuleft, refresh, setting, logo;
	TextView txtMenutitle;
	Context context;
	DrawerLayout drawer;

	public CustomActionbar(final Context context, AttributeSet attrs) {
		super(context, attrs);
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mActionLayout = (RelativeLayout) layoutInflater.inflate(R.layout.actionbar_layout, null);
		addView(mActionLayout);
		initview(mActionLayout);
	}

	void initview(View view) {
		menuleft = (ImageView) findViewById(R.id.actionbar_imageDrawer);
		refresh = (ImageView) findViewById(R.id.actionbar_imageRefresh);
		setting = (ImageView) findViewById(R.id.actionbar_imageSetting);
		logo = (ImageView) findViewById(R.id.actionbar_imageLogo);
		txtMenutitle = (TextView) findViewById(R.id.actionbar_textTitle);

		menuleft.setOnClickListener(clickListener);
	}

	public void setDrawer(DrawerLayout drawer) {
		this.drawer = drawer;
	}

	public void showMenu() {
		if (drawer.isDrawerVisible(START)) {
			drawer.closeDrawer(START);
		} else {
			drawer.openDrawer(START);
		}
	}

	public void setTitle(String title) {
		txtMenutitle.setText(title);
		logo.setVisibility(View.GONE);
	}

	public void setHome() {
		txtMenutitle.setVisibility(View.GONE);
		logo.setVisibility(View.VISIBLE);
	}

	OnClickListener clickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.actionbar_imageDrawer:
				showMenu();
				break;
			case R.id.actionbar_imageRefresh:
				break;
			case R.id.actionbar_imageSetting:
				break;
			default:
				break;
			}
		}
	};
}
